package com.easemob.helpdesk.widget.chatrow;

import android.app.Activity;
import android.content.Intent;
import android.view.View;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.easemob.helpdesk.activity.chat.MsgShowBigImage;
import com.easemob.helpdesk.activity.chat.ShowBigImage;
import com.easemob.helpdesk.adapter.ChatAdapter;
import com.easemob.helpdesk.adapter.UserChatAdapter;
import com.easemob.helpdesk.bean.MsgChat;
import com.easemob.helpdesk.utils.CommonUtils;
import com.easemob.helpdesk.widget.BubbleImageView;
import com.housekeeperapp.R;
import com.hyphenate.kefusdk.entity.HDMessage;

/**
 * Created by wsj on 2018/5/22.
 */

public class MsgImageViewHolder extends BaseMsgViewHolder {
    public BubbleImageView bImageView;
    public TextView tvPercentage;
    public ProgressBar pb;
    public ImageView ivStatus;
    public TextView tvUserNick;

    public MsgImageViewHolder(Activity activity, UserChatAdapter chatAdapter, View itemView) {
        super(activity, chatAdapter, itemView);

    }

    @Override
    public void handleViewMessage(final MsgChat message, int position) {

        Glide.with(activity).load(message.getUrl())
                .diskCacheStrategy(DiskCacheStrategy.RESOURCE).error(R.drawable.default_image)
                .override(CommonUtils.convertDip2Px(activity, 120), CommonUtils.convertDip2Px(activity, 120))
                .into(bImageView);

        bImageView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent();
                intent.setClass(activity, MsgShowBigImage.class);
                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                intent.putExtra("picpath", message.getUrl());
                intent.putExtra("msgid", message.getId() + message.getType());

                activity.startActivity(intent);
            }
        });

        pb.setVisibility(View.GONE);
        tvPercentage.setVisibility(View.GONE);
        if (ivStatus != null)
            ivStatus.setVisibility(View.GONE);
    }

    @Override
    protected void onFindViewById() {
        bImageView = findViewById(R.id.iv_sendPicture);
        tvPercentage = findViewById(R.id.percentage);
        pb = findViewById(R.id.progressBar);
        ivStatus = findViewById(R.id.msg_status);
        tvUserNick = findViewById(R.id.tv_userid);

    }
}
